//
//  FirstViewController.m
//  BlueFilters
//
//  Created by 零零壹 on 2016/11/28.
//  Copyright © 2016年 零零壹. All rights reserved.
//

#import "FirstViewController.h"
//#import "MyTabbarViewController.h"
#import "LoginViewController.h"
#import "RootViewViewController.h"

@interface FirstViewController ()<UIScrollViewDelegate>

@property(nonatomic,strong)UIPageControl *pageC;

@end

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];

    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,0, KscreenW, KscreenH)];
    scrollView.delegate = self;
    scrollView.pagingEnabled = YES;
    scrollView.bounces = NO;
    scrollView.contentSize = CGSizeMake(3*KscreenW, 0);
    scrollView.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:scrollView];

    self.pageC = [[UIPageControl alloc]initWithFrame:CGRectMake(0, KscreenH-60, 200, 50)];
    self.pageC.centerX = self.view.centerX;
    [self.view addSubview:self.pageC];
    self.pageC.numberOfPages = 3;
    self.pageC.currentPageIndicatorTintColor = UIColors(MainColor);
    self.pageC.pageIndicatorTintColor = UIColors(0xF0F0F0);

    UIImageView *image1 = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KscreenW, KscreenH)];
    image1.image = [UIImage imageNamed:@"welcome-1"];
    [scrollView addSubview:image1];

    UIImageView *imageV2 = [[UIImageView alloc]initWithFrame:CGRectMake(KscreenW, 0, KscreenW, KscreenH)];
    imageV2.image = [UIImage imageNamed:@"weicome-2"];
    [scrollView addSubview:imageV2];

    UIImageView *imageV3 = [[UIImageView alloc]initWithFrame:CGRectMake(KscreenW*2, 0, KscreenW, KscreenH)];
    imageV3.image = [UIImage imageNamed:@"welcome-3"];
    imageV3.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(change:)];
    [imageV3 addGestureRecognizer:tap];
    [scrollView addSubview:imageV3];
    
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView   // called on finger up as we are moving
{
    self.pageC.currentPage = scrollView.contentOffset.x/KscreenW;
}

-(void)change:(UITapGestureRecognizer *)tap
{
    UIImageView *imageV = (UIImageView *)tap.view;
    [UIView beginAnimations:@"" context:nil];   //开始动画
    [UIView setAnimationDelegate:self];
    CGAffineTransform curent =  imageV.transform;
    CGAffineTransform scale = CGAffineTransformScale(curent, 1.2,1.2);
    [UIView setAnimationDuration:1];
    [imageV setTransform:scale];
    [UIView commitAnimations];  //结束动画

    [UIView animateWithDuration:1.2 animations:^{
        imageV.alpha = 0;
    }];

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        UIWindow *window = [[UIApplication sharedApplication].windows firstObject];
        if ([[NSUserDefaults standardUserDefaults]objectForKey:kAccessToken])
        {
            RootViewViewController *root = [[RootViewViewController alloc]init];
            window.rootViewController = root;
        }else
        {
            LoginViewController *VC = [[LoginViewController alloc]init];
            window.rootViewController = VC;
        }
        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"First"];
    });
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
